<?php

class Damages_AuthData_Email implements Damages_AuthData_ILoginData {

  const PASSWORD_ENCODING_METHOD = 'sha256';

  private $email;
  private $password;

  public function __construct($email, $password) {
    $this->email = $email;
    $this->password = $password;
  }

  public function getUser() {
    return DamagesUsersQuery::create()
                    ->joinPermissions()
                    ->filterByEmail($this->email)
                    ->filterByPassword(self::crypt($this->password))
                    ->find()
                    ->getFirst();
  }

  public function getId() {
    return $this->email;
  }

  public static function crypt($data) {
    return hash(self::PASSWORD_ENCODING_METHOD, $data);
  }

}